﻿@page "/related-company"

@using ZLJ.Application.Share.AssociatedCompany

@using System.Reflection;
@attribute [ReuseTabsPage(Title = "客户档案")]
@attribute [Authorize(PermissionNames.BXJGBaseInfoAssociatedCompany)]

@inherits ZLJ.RCL.Components.ListBaseComponent<AssociatedCompanyDto, long, PagedAndSortedResultRequest<AssociatedCompanyCondition>>

<Flex Gap="FlexGap.Small" Vertical Justify="FlexJustify.SpaceBetween">
    <Flex Gap="FlexGap.Small" Justify="FlexJustify.SpaceBetween">
        @* 左侧 *@
        <Flex Gap="FlexGap.Small">
            @if (createIsGranted)
            {
                <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Plus" OnClick="BtnAddClick">新增</Button>
            }
            @if (deleteIsGranted)
            {
                @* 由于多选除了删除可能做其它操作，可能失误，所以虽然这里删除是两个步骤，依然加个确认比较靠谱 *@
                <Popconfirm Title="确定删除已选择的项吗?" OnConfirm="BtnDeleteClick">
                    <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Clear" Danger="true" Disabled="@ShouldDisableDelete" Loading=isDeleting>删除</Button>
                </Popconfirm>
            }
            @* @if (table != default)
            {
                var f = typeof(Table<AssociatedCompanyDto>).GetField("_shouldRender", BindingFlags.Instance | BindingFlags.NonPublic);
                var sdfsd = f.GetValue(table);
                @:@sdfsd
            } *@
        </Flex>
        @* 右侧 *@
        <Flex Gap="FlexGap.Small">
            @* <TreeSelectOu Style="min-width:10rem;" AllowClear Value="@GetAllInput.Filter.OuCode" ValueChanged="OnOuChanged" @ref=ou Disabled=IsLoading />
            <RadioGroup TValue="bool?" @bind-Value="@GetAllInput.Filter.IsStatic" OnChange="BtnSearchClick" Disabled=IsLoading>
            <Radio TValue="bool?" RadioButton="true" Value="@(default(bool?))">全部</Radio>
            <Radio TValue="bool?" RadioButton="true" Value="@(true)">预设</Radio>
            <Radio TValue="bool?" RadioButton="true" Value="@(false)">非预设</Radio>
            </RadioGroup> *@
            @*Search组件有问题，设置宽度会错位 *@
            @*  <Dropdown Trigger="@(new Trigger[] { Trigger.Hover })">
            <Overlay>
            <Menu>
            <MenuItem @key="LifeCycleStatus.Ready" OnClick="">
            准备就绪
            </MenuItem>
            <MenuItem>

            2nd menu item

            </MenuItem>
            <MenuItem>

            3rd menu item

            </MenuItem>
            </Menu>
            </Overlay>
            <ChildContent>
            <Button>Button <Icon Type="down" /></Button>
            </ChildContent>
            </Dropdown> *@
            @*  <RadioGroup TValue="bool?" @bind-Value="GetAllInput.Filter.LockStatus" OnChange="BtnSearchClick">
            <Radio RadioButton Value="@(default(bool?))">全部</Radio>
            <Radio RadioButton Value="(bool?)true">解锁</Radio>
            <Radio RadioButton Value="(bool?)false">锁定</Radio>
            </RadioGroup>
            <RadioGroup TValue="bool?" @bind-Value="GetAllInput.Filter.IsOnline" OnChange="BtnSearchClick">
            <Radio RadioButton Value="@(default(bool?))">全部</Radio>
            <Radio RadioButton Value="(bool?)true">在线</Radio>
            <Radio RadioButton Value="(bool?)false">离线</Radio>
            </RadioGroup> *@
            @* 下面设置LabelTemplate=Component1._overlayMenu要错位 *@
            @* <EnumSelect ItemTemplate=RenderFragments.LifeCycleStatusNull TEnum="LifeCycleStatus?" @bind-Value="@GetAllInput.Filter.LifeCycleStatus" OnSelectedItemChanged="BtnSearchClick" OnClearSelected="BtnSearchClick" AllowClear Placeholder="使用状态" Style="width:6.5rem;" /> *@
            @* <EnumRadioGroup TEnum="LifeCycleStatus?" @bind-Value="@GetAllInput.Filter.LifeCycleStatus" OnChange="BtnSearchClick"></EnumRadioGroup> *@
            <div style="width:14.5rem;">
                <Search Placeholder="名称/联系人/电话/地址等..." @bind-Value="@Keywords" OnChange=BtnSearchClick AllowClear="true"  Disabled=IsLoading />
            </div>
            <Tooltip Title="清空条件">
                <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Clear" OnClick="BtnClearFilterClick" Disabled=IsLoading></Button>
            </Tooltip>
            <Tooltip Title="刷新">
                <Button Type="@ButtonType.Default" Icon="@IconType.Outline.Reload" OnClick="BtnRefreshClick" Disabled=IsLoading></Button>
            </Tooltip>
        </Flex>
    </Flex>

    <Table @ref="table"
           TItem="AssociatedCompanyDto"
           Total="TotalCount"
           @bind-SelectedRows="SelectedItems"
           OnChange="OnQuery"
           DataSource="Items"
           PageIndex="PageIndex" AutoHeight
           PageSize="PageSize"
           Loading="IsLoading"
           RowClassName="@(r=>r.RowIndex%2==0?"even":"odd")"
           RemoteDataSource="true"
           RowKey="x=>x.Id"
           OnRow="OnRow"
           Size="TableSize.Small"
           Bordered="true"
           ScrollY="71.5vh"
           ScrollX="1550px">

        <Selection Key="@context.Id.ToString()" Width="50" Fixed="ColumnFixPlacement.Left" />
        <Column TData=AssociatedCompanyDto Title="行号" Width="60" Fixed="ColumnFixPlacement.Left">
            @(PageSize * (PageIndex - 1) + Items.IndexOf(context) + 1)
        </Column>
        <PropertyColumn Property="c=>c.Name" Sortable="true" DefaultSortOrder="SortDirection.Ascending" ShowSorterTooltip="false" Width="350" Fixed="ColumnFixPlacement.Left" />
        <PropertyColumn Property="c=>c.LevelDisplayName" ShowSorterTooltip="false" Width="100" Sortable Align="ColumnAlign.Center" />
        <PropertyColumn Property="c=>c.AreaDisplayName" ShowSorterTooltip="false" Width="200" Sortable Align="ColumnAlign.Center" />
        <PropertyColumn Property="c=>c.LinkMan" ShowSorterTooltip="false" Width="100" />
        <PropertyColumn Property="c=>c.LinkPhone" ShowSorterTooltip="false" Width="120" Align="ColumnAlign.Center" />
        <PropertyColumn Property="c=>c.Address" ShowSorterTooltip="false"  />
        <ActionColumn Title="操作" Width="160" Fixed="ColumnFixPlacement.Right">
            @* ButtonGroup设置Size好像没啥卵用 *@
            <ButtonGroup Size="@ButtonGroupSize.Small">
                <Button Size="@ButtonSize.Small" Type="@ButtonType.Primary" OnClick="x=>BtnDetailClick(context)">详情</Button><br />
                @if (updateIsGranted)
                {
                    <Button Size="@ButtonSize.Small" OnClick="x=>BtnEditClick(context)">修改</Button>
                }
                @if (deleteIsGranted)
                {
                    <Popconfirm Title="确定删除此项吗?"
                                OnConfirm="()=>BtnDeleteItemClick(context)">
                        <Button Size="@ButtonSize.Small" Danger="true">删除</Button>
                    </Popconfirm>
                }

            </ButtonGroup>
        </ActionColumn>
    </Table>
</Flex>

@* <AbpCreateDialog TAppService="IPostAppService" TEntityDto="PostDto" TPrimaryKey="int"
                 TGetAllInput="PagedAndSortedResultRequest<PagedPostResultRequestDto>"
                 TCreateInput="CreatePostDto" TUpdateInput="PostEditDto" TCreateComponent="Create"
>

</AbpCreateDialog>
 *@

@{
    RenderFragment renderFragment =@<Template>
        <SectionOutlet SectionName=@(this.GetHashCode() + "-create-btns") />
        <Button OnClick="CloseCreateDialog">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose="true"   Footer="renderFragment" @bind-Visible="isCreateDialogVisible" 
Draggable="true" Class="frm-dal" 
        Width=@("40vw")
AfterClose="OnAfterCloseDialog">
    <TitleTemplate>
        <Icon Type="plus" Theme="IconThemeType.Outline" />
        新增@(FuncName)
    </TitleTemplate>

    <ChildContent>
        <SectionOutlet SectionName=@(this.GetHashCode() + "-create-body") />
        <Create OnAddEnd="OnAddEnd" Master="this.GetHashCode()"  />
    </ChildContent>
</Modal>

@{
    RenderFragment renderFragment1 =@<Template>
        <SectionOutlet SectionName=@(this.GetHashCode() + "-detail-update-btns") />
        <Button OnClick="CloseUpdateOrDetail">关闭</Button>
    </Template>;
}
<Modal DestroyOnClose="true"
       @bind-Visible="isShowDetailUpdate"
       Draggable="true"
       Title="设备详情"
       Width=@("40vw") Class="frm-dal"
       Maximizable
       AfterClose="OnAfterCloseDialog"
       Footer="renderFragment1"
       DefaultMaximized=false>
    @*<TitleTemplate>
    <SectionOutlet SectionName=@(FuncName + "-detail-update-title") />
    </TitleTemplate> *@
    <ChildContent>
        <SectionOutlet SectionName=@(this.GetHashCode() + "-detail-update-body") />
        <DetailUpdate Id=@detailUpdateId IsEdit=isEdit OnDeleted=OnDetailUpdate OnUpdated=OnDetailUpdate Master="this.GetHashCode()" />
    </ChildContent>
</Modal>